
$(function() {
});

var Conference = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];

				var body = { };
				
				body.t1 = form.date1.value + " " + form.time1.value;
				body.t2 = form.date2.value + " " + form.time2.value;
				body.address = form.address.value;
								
				body.name = form.name.value;
				body.content = form.content.value;
				
				body.emp = form.emp.value;

				$(this).dialog("close");

				$.post('info.php?do=Conference.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_add(url, title, xy);
	},	

	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);
						
		var c1 = 'info.php?do=Conference.edit&id=' + id;	
		var c2 = 'info.php?do=Conference.view&id=' + id;
		
		var c3 = 'info.php?do=ConferenceEmp.emp&id=' + id;
		var c4 = 'info.php?do=ConferenceEmp.absent&id=' + id;
		
		var c8 = 'info.php?do=Conference.notice&id=' + id;

		var a1 = ['编辑信息', 'url', 'Conference.dialog_edit_', '720x450'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '600x400'];

		var a3 = ['应到人员', 'url', 'Conference.dialog_emp', '650x500'];
		var a4 = ['缺席人员', 'url', 'Conference.dialog_absent', '650x500'];
		
		var a8 = ['会议通知', 'url', 'Conference.dialog_notice', '650x500'];
		
		if (status < 3) {
			var d1 = 'info.php?do=Conference.verify&id=' + id;
			var b1 = ['审核信息', 'url', 'Conference.dialog_verify', '650x450'];
			
			var s = d1 + ", " + c1 + ", " + c2 + ", " + c3 + ", " + c4 + ", " + c8;

			return this.popup_(e, [b1, a1, a2, a3, a4, a8], s);
		}
		
		var s = c2 + ", " + c8;

		return this.popup_(e, [a2, a8], s);
	},
	
	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var c2= 'info.php?do=Conference.upload&id=' + id;
		var a2 = ['上传附件', 'url', 'Common.dialog_upload', '600x420'];
		
		var ss = 'info.php?do=Conference.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Conference.dialog_ss', '400x200'];
		
		s += ", " + c2 + ", " + ss;
		
		a.push(a2);
		a.push(bb);
		
		return popup(e, a, s);
	},

	/**
	 * 修改状态
	 */
	dialog_ss: function (url, title, xy) {
		result = Common.result();
		$.getJSON('info.php?do=Conference.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'info.php?do=Conference.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_verify: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('info.php?do=Conference.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},		

					"不通过": function() {
						if (!confirm("确认是否不通过？")) {
							return false;
						}				
						
						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.content = form.content.value;
						body.status = 9;
						
						$(this).dialog("close");
						
						var url = 'info.php?do=Conference.verifyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					},
					
					"通过": function() {
						if (!confirm("确认是否通过？")) {
							return false;
						}				

						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.content = form.content.value;
						body.status = 8;
						
						$(this).dialog("close");

						var url = 'info.php?do=Conference.verifyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});	
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('info.php?do=Conference.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},
					
					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
						
						var form = $("#form_edit")[0];
						
						var body = {};
						body.id = form.id.value;
						body.t1 = form.date1.value + " " + form.time1.value;
						body.t2 = form.date2.value + " " + form.time2.value;
						body.address = form.address.value;
										
						body.name = form.name.value;
						body.content = form.content.value;
						
						body.emp = form.emp.value;
						
						body.status = form.status.value;
		
						$(this).dialog("close");
		
						var url = 'info.php?do=Conference.editPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
		
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
		
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	download: function (key) {
		if (!confirm("确认是否下载？若下载，建议先另存，再打开。")) {
			return false;
		}
		
		var url = 'info.php?do=Conference.download&key=' + key;
		jswin(url, 'save', '800x600');
		
		return true;
	},
	
	file: function (id, key) {
		if (!confirm("确认是否删除？")) {
			return false;
		}
		
		var c6 = 'info.php?do=Conference.upload&id=' + id;
		
		var url = 'info.php?do=Conference.file';
		var body = { };
		body.key = key;
		
		$.post(url, body, function(data) {
			// alert(data);
			$.get(c6, function(data) {
				$('#dialog_edit').html(data);
			});
		});
		
		return true;
	},
	
	dialog_absent: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('info.php?do=Conference.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},
		
					"提交": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
						
						var foo = [];
						
						$("#emp option").each(function(i, n) {
							foo[i] = $(n).val();
						});
						
						var form = $("#form_edit")[0];
		
						var body = { };
						body.id = form.id.value;
						body.list = foo.join(",");
		
						$(this).dialog("close");
		
						var url = 'info.php?do=ConferenceEmp.absentPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
		
						$.post(url, body, function(data) {
							// $(result).html(data);
							alert("更新成功！");
						});
					}
				});
		
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_emp: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('info.php?do=Conference.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},
		
					"提交": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
						
						var foo = [];
						
						$("#emp option").each(function(i, n) {
							foo[i] = $(n).val();
						});
						
						var form = $("#form_edit")[0];
		
						var body = { };
						body.id = form.id.value;
						body.list = foo.join(",");
		
						$(this).dialog("close");
		
						var url = 'info.php?do=ConferenceEmp.empPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
		
						$.post(url, body, function(data) {
							// $(result).html(data);
							alert("更新成功！");
						});
					}
				});
		
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_notice: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('info.php?do=Conference.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() { 
						$(this).dialog("close");
					},
					
					"发送": function() {
						if (!confirm("确认是否群发通知？")) {
							return false;
						}
						
						var foo = [];
						
						$("#emp option").each(function(i, n) {
							foo[i] = $(n).val();
						});
						
						var form = $("#form_edit")[0];
		
						var body = { };
						body.id = form.id.value;
						body.list = foo.join(",");
						
						var form = $("#form_add")[0];
						body.content = form.content.value;
		
						$(this).dialog("close");
		
						var url = 'info.php?do=Conference.noticePost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
		
						$.post(url, body, function(data) {
							// $(result).html(data);
							alert("发送成功！");
						});
					}
				});
		
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	}
};
